<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div class="box1">测试的div盒子</div>
  <div class="box2">测试的div盒子</div>

  <script>
    // 获取注册事件DOM对象
    const box1 = document.querySelector('.box1')
    const box2 = document.querySelector('.box2')

    // 给 DOM 对象注册事件(事件源  事件类型  事件处理函数)
    box1.addEventListener('click', function () {
      console.log('点击了！');
      // box.style.color = 'red'

      this.style.color = 'green'
    })

    box2.addEventListener('click', () => {
      console.log('点击了！');
      box2.style.color = 'red'

      // 箭头函数中 没有 this 
      // this.style.color = 'green'
    })

  </script>
</body>

</html>